<?php

namespace App\Admin\Extensions\Tools;

use Encore\Admin\Admin;
use Encore\Admin\Grid\Tools\AbstractTool;
use Illuminate\Support\Facades\Request;

class OrderStatus extends AbstractTool
{
    public $options = [
        '0' => '全部订单',
        '1' => '待付款',
        '2' => '待发货',
        '3' => '已关闭',
        '4' => '已发货',
        '5' => '已完成',
    ];

    public function __construct($options = [])
    {
        if ($options) {
            $this->options = $options;
        }
    }

    public function script()
    {
        $url = Request::fullUrlWithQuery(['status' => '_status_']);

        return <<<EOT

$('input:radio.grid-view').change(function () {

    var url = "$url".replace('_status_', $(this).val());

    $.pjax({container:'#pjax-container', url: url });

});

EOT;
    }

    public function render()
    {
        Admin::script($this->script());

        $options = $this->options;

        return view('admin.tools.order-status', compact('options'));
    }
}
